package com.explorati.LeetCode54.kthLargest;


import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 20:53 2020/9/13 0013
 * @ Description ：
 */
public class Solution {
    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }

    /**
     * 给定一棵二叉搜索树，请找出其中第k大的节点
     * @param root
     * @param k
     * @return
     */
    int res, k;
    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        inOrder(root);
        return res;
    }

    private void inOrder(TreeNode root) {
        if(root == null) {
            return ;
        }

        inOrder(root.right);

        if(--k == 0) {
            res = root.val;
        }
        inOrder(root.left);
    }

}
